#!/bin/bash

# 判断目录是否存在
path=/home/shell/mypath
[ ! -d "$path" ] && mkdir $path
cat <<END
	1.[install npm]
	2.[install cnpm]
	3.[exit]
	pls input the num you want;
END
# 接收用户输入
read num
# 如果输入的不是数字
expr $num + 1 &> /dev/null
[ $? -ne 0 ] && {
	echo "the num must be [1,2,3]"
	exit 1
}

[ $num -eq 1 ] && {
	echo "Starting install npm waiting......"
	sleep 2
	# 是否存在或者有执行权限
	[ -x "$path/npm.sh" ] || {
		echo "The file does not exist or can't be exec."
		exit 1
	}
	source $path/npm.sh
	exit $?
}
[ $num -eq 2 ] && {
        echo "Starting install cnpm waiting......"
        sleep 2
        [ -x "$path/cnpm.sh" ] || {
                echo "The file does not exist or can't be exec."
                exit 1
        }
        source $path/cnpm.sh
        exit $?
}
[ $num -eq 3 ] && {
	echo "Bye!!!"
	exit 3
}
# 正则匹配是否1-3
[[ ! "$num =~ [1-3]" ]] && {
	echo "The num you input must be [1,2,3]"
	exit 4
} 





